package com.bsj.travel.mqtt;

import com.bsj.travel.constant.ServiceNameConstants;
import com.bsj.travel.def.global.JsonResult;
import com.bsj.travel.def.mqtt.message.SendMqttMsg;
import com.bsj.travel.def.mqtt.message.node.MqttServerNode;
import com.bsj.travel.mqtt.factory.RemoteMqttBrokerFallbackFactory;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.List;

/**
 * @author yinhao
 * @version 1.0
 * @description mqtt节点客户端信息
 * @date 2023/11/9
 */
@FeignClient(contextId = "remoteMqttBrokerService", value = ServiceNameConstants.MQTT_BROKER_SERVICE, fallbackFactory = RemoteMqttBrokerFallbackFactory.class)
public interface RemoteMqttBrokerService {

    /**
     * 获取全部服务节点
     * @return
     */
    @GetMapping(value = "/broker/queryNodes")
    JsonResult<List<MqttServerNode>> queryNodes();

    /**
     * 获取所有节点在线的客户端数量
     * @return
     */
    @GetMapping(value = "/broker/queryOnlineClientSize")
    JsonResult<Long> queryOnlineClientSize();

    /**
     * 获取对应节点客户端在线数量
     * @param nodeName
     * @return
     */
    @GetMapping(value = "/broker/queryNodeOnlineSize/{nodeName}")
    JsonResult<Long> queryNodeOnlineSize(@PathVariable(value = "nodeName", required = false) String nodeName);

    /**
     * 用于内部集群间MQTT消息下行
     * @param sendMqttMsg
     * @return
     */
    @PostMapping(value = "/broker/sendMsg")
    JsonResult<Boolean> sendMsg(@RequestBody SendMqttMsg sendMqttMsg);

    /**
     * 用于内部集群间MQTT状态管理
     * @param sendMqttMsg
     * @return
     */
    @PostMapping(value = "/broker/mqttConnectTake")
    JsonResult<Boolean> mqttConnectTake(@RequestBody SendMqttMsg sendMqttMsg);

}
